package com.guli.mall.pms.controller;

import java.util.Arrays;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;

import com.guli.mall.pms.entity.CategoryEntity;
import com.guli.mall.pms.service.CategoryService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;


/**
 * 商品三级分类
 *
 * @author 罗俊华
 * @email 1007052116@qq.com
 * @date 2020-09-17 11:37:23
 */
@RestController
@RequestMapping("pms/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    @GetMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取category分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size) {
        PageUtils page = categoryService.queryPage(currentPage,size);

        return R.ok().put("page", page);
    }



    @GetMapping("/info/{catId}")
    @ApiOperation("根据catId获取Category")
    public R info(@PathVariable("catId") Long catId) {
            CategoryEntity category = categoryService.getById(catId);

        return R.ok().put("category", category);
    }

    @PostMapping("/save")
    @ApiOperation("插入Category")
    public R save(@RequestBody CategoryEntity category) {
            categoryService.save(category);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据catId更新Category")
    public R update(@RequestBody CategoryEntity category) {
            categoryService.updateById(category);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据catId批量删除Category")
    public R delete(@RequestBody Long[] catIds) {
            categoryService.removeByIds(Arrays.asList(catIds));

        return R.ok();
    }

}
